#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import os
import socket
class FTPClient(object):
    def __init__(self,argv):
        self.args = argv
        print self.args     #==>['bin\\ftp_client.py', '-s', '127.0.0.1', '-p', '9999']
        self.parse_argv()   #调用自身方法

    def parse_argv(self):
        if len(self.args) <5:
            self.help_msg()     #如果参数小于5个，输出帮助方法
        else:
            mandatory_fields = ["-s","-p"]  #mandatory必须的
            for i in mandatory_fields:
                if i not in sys.argv:
                    sys.exit("The argument [%s] is mandatory!" %i)
            try:
                ftp_host = self.args[self.args.index("-s")+1]
                ftp_port = int(self.args[self.args.index("-p")+1])
            except (IndexError,ValueError) as e:
                print "\033[31;1m%s\033[0m" % e
                self.help_msg()
            print ftp_host,ftp_port     #==>127.0.0.1 9999
    def help_msg(self):
        help_msg = '''
        -s ftp_server_addr      :the ftp server you want to connect,mandatory
        -p ftp port             :ftp port ,mandatory
        '''

        sys.exit(help_msg)
